package com.software.seakdream.service;

import com.software.seakdream.entity.UserInfo;
import com.software.seakdream.repository.UserInfoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class UserInfoServiceImpl implements UserInfoService{
    @Autowired
    private UserInfoRepository userInfoRepository;

    @Override
    public List<UserInfo> queryAllUser() {
        return userInfoRepository.queryAllUser();
    }

    @Override
    public UserInfo createUserInfo(UserInfo userInfo) {
        userInfo.setUserId(UUID.randomUUID().toString());
        userInfo.setIfVip("2");
        userInfo.setPoints(1000);
        userInfoRepository.createUserInfo(userInfo);
        return userInfo;
    }

    @Override
    public UserInfo queryUserByPhone(String phone) {
        UserInfo query = userInfoRepository.queryUserByPhone(phone);
        return query;
    }

    @Override
    public UserInfo getUserInfo(String id) {
        UserInfo userInfo = userInfoRepository.getUserInfo(id);
        return userInfo;
    }

    @Override
    public void setHeadshot(String userId, String headshot) {
        userInfoRepository.setHeadshot(userId,headshot);

    }

    @Override
    public UserInfo login(UserInfo user) {
        UserInfo userInfo = userInfoRepository.login(user);

        if (userInfo != null){
            return userInfo;
        }
        throw new RuntimeException("登陆失败");
    }

    @Override
    public void setSex(String userId, String sex) {
        userInfoRepository.setSex(userId,sex);
    }

    @Override
    public void setDescription(String userId, String description) {
        userInfoRepository.setDescription(userId,description);
    }

    @Override
    public void setBirthday(String userId, String birthday) {
        userInfoRepository.setBirthday(userId,birthday);
    }

    @Override
    public void setLocation(String userId, String location) {
        userInfoRepository.setLocation(userId,location);
    }

    @Override
    public void setNickName(String userId, String nickName) {
        userInfoRepository.setNickName(userId,nickName);
    }

    @Override
    public void updateIfVip(String userId, String ifVip) {
        userInfoRepository.updateIfVip(userId,ifVip);
    }

    @Override
    public void updateBeginTime(String userId, Date date) {
        userInfoRepository.updateBeginTime(userId,date);
    }

    @Override
    public void updateEndTime(String userId, Date date) {
        userInfoRepository.updateEndTime(userId,date);
    }

    @Override
    public void updatePoints(String userId, Integer points) {userInfoRepository.updatePoints(userId,points);}

    @Override
    public Integer getPointsById(String userId) {
        Integer points = userInfoRepository.getPointsById(userId);
        return points;
    }
}
